package vip.xiaozhao.paotui.controller.upload;

import lombok.extern.slf4j.Slf4j;
import org.json.JSONObject;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import vip.xiaozhao.paotui.controller.BaseController;
import vip.xiaozhao.paotui.intf.dto.ResponseDO;
import vip.xiaozhao.paotui.intf.utils.cos.COSUtils;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@RestController
@RequestMapping("/api/cos")
@Slf4j
public class UploadCOSController extends BaseController {


    //cos的老的前端再次签名方案
    @RequestMapping("/upload/directSign")
    public ResponseDO getSign(HttpServletRequest request)  {

        int currentUserId = getCurrentUserId(request);
        if (currentUserId < 0) {
            return new ResponseDO(false, NOT_LOGIN, null);
        }
        try {
            JSONObject jsonObject = COSUtils.genCOSPlubParams();
            return  new ResponseDO(true, SUCCESS, jsonObject.toMap());
        }catch (IOException e) {
            log.error("fail to sign", e);
            return new ResponseDO(false, "获取签名失败", null);
        }
    }


    //cos的新的后端直播签名方案, 要传入png等
    @RequestMapping("/upload/directSign1")
    public ResponseDO getSign(String postFix, HttpServletRequest request)  {
        return  ResponseDO.success(null);
    }



}

